﻿@using GoodMan.Infrastructure.Entities.Entity;
@using GoodMan.Infrastructure.Entities.Contract;
@using GoodMan.Tool.Framework;
@using GoodMan.Portal.Biz;
@{
    Layout = "~/Views/Shared/_Main.cshtml";
    //  decimal totalMoney = ViewBag.TotalMoney == null ? 0 : ViewBag.TotalMoney;
    List<OrderDetail> orderDetailList = ViewBag.OrderDetails;
    var Currentuser = ViewBag.User == null ? new User() : ViewBag.User;
    var areacode = ViewBag.areaCode;
    string message = ViewBag.Message == null ? "" : ViewBag.Message;
    string postUrl="/shop/SubmitOrder";
    if (areacode==10){
        postUrl = "/shop/SubmitOrderFastFood";
    }

    decimal limitprice = ViewBag.limitprice == null ? 5 : ViewBag.limitprice;
}
@section head{
    <style type="text/css">
        .text
        {
            width: 30px;
            height: 16px;
            border: 1px solid #ccc;
            padding: 2px;
            text-align: center;
        }
    </style>
    <script type="text/javascript">
        var r = /^[0-9]*[1-9][0-9]*$/;
        function changeNumFastFood(id, price, j) {
            // alert(id + price);
            //var j = $("#no" + id).val();
            var num = $("input[name='Number']").val();
            //alert(j);
            if (!r.test(num)) {
                $("input[name='Number']").val("1");
                num = 1;
                alert("请输入大于等于1的正整数");

            }
            var totalNum = 0;
            $("[id='pnum" + id + "']").each(function () {
                var value = $(this).val();
                totalNum = totalNum + value * 1;
            });
            var money = num * price;
            $("#money" + j).html(fffmoney(money, 2));
            var totalMoney = 0;
            var ids = $("#productIds").val().split(',');
            for (var i = 0; i < ids.length; i++) {
                if (ids[i] != "") {
                    //j = $("#no" + ids[i]).val();
                    var temp = $("#money" + ids[i]).html();
                    totalMoney = totalMoney + temp * 1;
                }
            }
            //alert(totalMoney);
            $("#money").html(fffmoney(totalMoney, 2));
            $("#totalmoney").val(fffmoney(totalMoney, 2));
        }

        function changeNum(id, price, j) {
            // alert(id + price);
            //var j = $("#no" + id).val();
            var num = $("input[name='num" + j + "']").val();
            //alert(j);
            if (!r.test(num)) {
                $("input[name='num" + j + "']").val("1");
                num = 1;
                alert("请输入大于等于1的正整数");

            }
            var totalNum = 0;
            $("[id='pnum" + id + "']").each(function () {
                var value = $(this).val();
                totalNum = totalNum + value * 1;
            });

            var remain = $("#remain" + j).val();
            if (totalNum * 1 > remain * 1) {
                var tempRemain = num - (totalNum - remain * 1);
                $("input[name='num" + j + "']").val(tempRemain);
                num = tempRemain;
                $("#tip" + j).html("仅剩" + tempRemain + "件");
            }
            var money = num * price;
            $("#money" + j).html(fffmoney(money, 2));
            var totalMoney = 0;
            var ids = $("#productIds").val().split(',');
            for (var i = 0; i < ids.length; i++) {
                if (ids[i] != "") {
                    //j = $("#no" + ids[i]).val();
                    var temp = $("#money" + ids[i]).html();
                    totalMoney = totalMoney + temp * 1;
                }
            }
            //alert(totalMoney);
            $("#money").html(fffmoney(totalMoney, 2));
            $("#totalmoney").val(fffmoney(totalMoney, 2));
        }

        function changeInNum(id, price) {
            // alert(id + price);
            var num = $("#innum" + id).val();

            if (!r.test(num)) {
                $("#innum" + id).val("1");
                num = 1;
                alert("请输入大于等于1的正整数");
            }

            //            if (num == "" || num <= 0) {
            //                $("#innum" + id).val("1");
            //                num = 1;
            //                alert("数量不能为空且必须大于等于1");
            //            }

            var remain = $("#inremain" + id).val();
            if (num * 1 > remain * 1) {
                $("#innum" + id).val(remain);
                num = remain;
                $("#intip" + id).html("仅剩" + remain + "件");
            }
            var money = num * price;
            $("#inmoney" + id).html(money);
            var totalMoney = 0;
            var ids = $("#IntegratIds").val().split(',');
            for (var i = 0; i < ids.length; i++) {
                if (ids[i] != "") {
                    var temp = $("#inmoney" + ids[i]).html();
                    totalMoney = totalMoney + temp * 1;
                }
            }
            $("#inmoney").html(totalMoney);
            $("#intotalmoney").val(totalMoney);
        }

        function fmoney(s, n) {
            n = n > 0 && n <= 20 ? n : 2;
            s = parseFloat((s + "").replace(/[^\d\.-]/g, "")).toFixed(n) + "";
            var l = s.split(".")[0].split("").reverse(),
            r = s.split(".")[1]; t = "";
            for (i = 0; i < l.length; i++) {
                t += l[i] + ((i + 1) % 3 == 0 && (i + 1) != l.length ? "," : "");
            } return t.split("").reverse().join("") + "." + r;
        }
        function fffmoney(s, n) {
            n = n > 0 && n <= 20 ? n : 2;
            s = parseFloat((s + "").replace(/[^\d\.-]/g, "")).toFixed(n) + "";
            var l = s.split(".")[0].split("").reverse();
            var r = s.split(".")[1];
            var t = "";
            for (i = 0; i < l.length; i++) {
                t += l[i] + "";
            } return t.split("").reverse().join("") + "." + r;

        }
        
    </script>
}
<div class="container">
    <ul class="breadcrumb">
        <li><a href="../home/index">首页</a> <span class="divider">></span></li>
        <li class="active">订单确认</li>
    </ul>
    <form action="@postUrl" id="formSo" name="formso" method="post">
    <input type="hidden" name="areacode" value="@areacode" />
    <div class="breadcrumb">
        <div style="vertical-align: middle">
            <span style="font-size: 15px;"><strong>配送信息</strong></span></div>
        <div style="margin-bottom: 5px; margin-top: 10px">
            <span class="key">收货人：</span><span><input type="text" id="userRealName" name="userRealName" value="@Currentuser.RealName" /></span></div>
        <div style="margin-bottom: 5px;">
            <span class="key">电&nbsp;&nbsp;&nbsp;话：</span><span><input type="text" id="phone" name="phone" value="@Currentuser.Phone" /></span></div>
        <div style="margin-bottom: 5px;">
            <span class="key">地&nbsp;&nbsp;&nbsp;址：</span><span><select name="domitory" id="domitory">
                @{
                    List<Dormitory> dormitories = ViewBag.FloorList;
                    if (dormitories != null)
                    {
                        int j = 0;
                        foreach (var item in dormitories)
                        {
                            if (Currentuser.FloorId == item.Id)
                            {
                    <option value="@item.Id" selected="selected">@item.Name</option>
                            }
                            else
                            {
                                if (j == 0)
                                {
                    <option value="@item.Id" selected="selected">@item.Name</option>
                                }
                                else
                                {
                    <option value="@item.Id" >@item.Name</option>
                                }
                            }
                            j++;
                        }
                    }
                }
            </select></span></div>
        <div style="margin-bottom: 5px;">
            <span class="key">详细地址：</span><span><input type="text" name="address" id="address" 
                style="width: 500px" value="@Currentuser.Dormitory" /></span></div>
    </div>
    <div class="breadcrumb">
        @{
            if (areacode == 10)
            {
                <input type="hidden" name="Catering" value="@orderDetailList[0].Catering" />
                <input type="hidden" name="ProductId" value="@orderDetailList[0].ProductId" />
            
            <div>
                <span style="font-size: 15px;"><strong>商品信息</strong></span></div>
            <div style="margin-bottom: 5px;">
                <span class="key">备注：</span><span><input type="text" name="remark" id="remark"  style="width: 700px" value="@ViewBag.remark" /></span></div>
            <table class="table">
                <thead>
                    <tr>
                        <th style="text-align: center">
                            序号
                        </th>
                        <th>
                            商品名称
                        </th>
                        <th>
                            单价
                        </th>
                        <th style="text-align: center">
                            数量
                        </th>
                        <th style="text-align: center">
                            小计(元)
                        </th>
                    </tr>
                </thead>
                <tbody>
                    @{
                decimal totalMoney = 0;
                if (orderDetailList != null && orderDetailList.Any())
                {
                    int j = 1;
                    string ids = "";
                    CateringSet catering = new CateringSet();
                    foreach (var item in orderDetailList)
                    {
                        ids = ids + j + ",";
                        decimal money = item.Price * item.Num;
                        string productName = item.ProductName + item.verValue;
                        totalMoney = totalMoney + money;
                        catering = item.Catering.ToObject<CateringSet>();
                        <tr>
                            <td style="text-align: center">
                                @j
                            </td>
                            <td>
                                @productName
                                <input type="hidden" name="ver@(j)" id="ver@(j)" value="@item.verValue" />
                                <input type="hidden" name="productid@(j)" id="productid@(j)" value="@item.ProductId" />
                            </td>
                            <td>
                                &yen;@item.Price
                            </td>
                            <td style="text-align: center; vertical-align: middle">
                                <input type="text" id="pnum@(item.ProductId)" name="Number"  onkeyup="changeNumFastFood(@item.ProductId,@item.Price,@j)" maxlength="5"  class="text"  style="width:30px;height:12px;" value="@item.Num"/><br />
                            </td>
                            <td style="text-align: center; color: #DC143C;">
                                &yen;<span id="money@(j)" name="money@(j)">@money</span>
                            </td>
                        </tr>
                    }
                        <input type="hidden" name="productIds" id="productIds" value="@ids" />
                   
                        
                    if (catering != null && catering.cateringList != null && catering.cateringList.Any())
                    {
                        <tr>
                            <td colspan="5" style="font-weight: bold;">
                                配菜信息
                            </td>
                        </tr>
                        <tr>
                            <td colspan="5">
                                @{
                    
                        foreach (var cItem in catering.cateringList)
                        {
                                    <div>
                                        @cItem.caterCategory&nbsp &nbsp;&nbsp;</div>
                                    <div>
                                        @{
                            foreach (var ciItem in cItem.cateringInfoList)
                            {
                                            <span>菜名:<b><font color="#333399">@ciItem.caterName</font></b>&nbsp;&nbsp;价格:&yen;@ciItem.caterPrice&nbsp;
                                                &nbsp;份数:<font color="#ff0000">@ciItem.caterNumber</font></span>
                            }
                                        }
                                    </div>
                        }
                    
                                }
                            </td>
                        </tr>
                    }
                    
                        <tr>
                            <td colspan="4" style="text-align: right; font-weight: bold;">
                                总金额
                            </td>
                            <td style="text-align: center; font-size: 19px; color: #DC143C; font-weight: bold;">
                                &yen;<span id="money" name="money">@totalMoney</span><input type="hidden" name="Money" id="totalmoney" value="@totalMoney" />
                            </td>
                        </tr>
                    
                }
                    }
                </tbody>
            </table>
            }
            else
                if (areacode != 3)
                {
       
            <div>
                <span style="font-size: 15px;"><strong>商品信息</strong></span></div>
            <div style="margin-bottom: 5px;">
                <span class="key">备注：</span><span><textarea name="remark" id="remark" rows="2" style="width: 500px">@ViewBag.remark</textarea></span></div>
            <table class="table">
                <thead>
                    <tr>
                        <th style="text-align: center">
                            序号
                        </th>
                        <th>
                            商品名称
                        </th>
                        <th>
                            单价
                        </th>
                        <th style="text-align: center">
                            数量
                        </th>
                        <th style="text-align: center">
                            小计(元)
                        </th>
                    </tr>
                </thead>
                <tbody>
                    @{
                    decimal totalMoney = 0;
                    if (orderDetailList != null && orderDetailList.Any())
                    {
                        int j = 1;
                        string ids = "";
                        foreach (var item in orderDetailList)
                        {

                            if (item.AreaCode != GoodMan.Infrastructure.Entities.Enum.AreaCode.Integration)
                            {
                                ids = ids + j + ",";
                                decimal money = item.Price * item.Num;
                                string productName = item.ProductName + item.verValue;
                                totalMoney = totalMoney + money;
                        <tr>
                            <td style="text-align: center">
                                @j
                            </td>
                            <td>
                                @productName
                                <input type="hidden" name="ver@(j)" id="ver@(j)" value="@item.verValue" />
                                <input type="hidden" name="productid@(j)" id="productid@(j)" value="@item.ProductId" />
                            </td>
                            <td>
                                &yen;@item.Price
                            </td>
                            <td style="text-align: center; vertical-align: middle">
                                <input type="text" id="pnum@(item.ProductId)" name="num@(j)" onkeyup="changeNum(@item.ProductId,@item.Price,@j)" maxlength="5"  class="text"  style="width:30px;height:12px;" value="@item.Num"/><br />
                                <span id="tip@(j)" style="color:Red;font-size:9px"></span>
                                <input type="hidden" id="remain@(j)" name="remain@(j)" value="@item.productRemain" />
                            </td>
                            <td style="text-align: center; color: #DC143C;">
                                &yen;<span id="money@(j)" name="money@(j)">@money</span>
                            </td>
                        </tr>
                       
                            }
                            j++;

                        }
                        <input type="hidden" name="productIds" id="productIds" value="@ids" />
                        <tr>
                            <td colspan="4" style="text-align: right; font-weight: bold;">
                                总金额
                            </td>
                            <td style="text-align: center; font-size: 19px; color: #DC143C; font-weight: bold;">
                                &yen;<span id="money" name="money">@totalMoney</span><input type="hidden" name="totalmoney" id="totalmoney" value="@totalMoney" />
                            </td>
                        </tr>
                        <tr><td colspan="5" style="text-align: right;color:Red;">
                        <span style="color:red;">如果购物不足 @limitprice 元，请自行前往楼栋售货员处提货并付款。</span></td>
                        </tr>
                    
                    }
                    }
                </tbody>
            </table>
                }
            if (areacode == 3)
            {
            
      
            <div>
                <span style="font-size: 15px;"><strong>积分兑换</strong></span></div>
            <div style="margin-bottom: 5px;">
                <span class="key">备注：</span><span><textarea name="remark" id="remark" rows="2" style="width: 500px">@ViewBag.remark</textarea></span></div>
            <table class="table">
                <thead>
                    <tr>
                        <th style="text-align: center">
                            序号
                        </th>
                        <th>
                            商品名称
                        </th>
                        <th>
                            积分
                        </th>
                        <th style="text-align: center">
                            数量
                        </th>
                        <th style="text-align: center">
                            小计(分)
                        </th>
                    </tr>
                </thead>
                <tbody>
                    @{
                int totalintegrate = 0;
                if (orderDetailList != null && orderDetailList.Any())
                {
                    int j = 1;
                    string inids = "";
                    foreach (var item in orderDetailList)
                    {

                        if (item.AreaCode == GoodMan.Infrastructure.Entities.Enum.AreaCode.Integration)
                        {
                            inids = inids + item.ProductId + ",";
                            decimal money = item.Price * item.Num;
                            string productName = item.ProductName + item.verValue;
                            int integrate = Convert.ToInt32(item.Price * SupportBiz.GetCostRank());
                            int sumintegrate = integrate * item.Num;
                            totalintegrate = totalintegrate + sumintegrate;
                        <tr>
                            <td style="text-align: center">
                                @j
                            </td>
                            <td>
                                @productName
                                <input type="hidden" name="inver@(item.ProductId)" id="inver@(item.ProductId)" value="@item.verValue" />
                            </td>
                            <td>
                                @integrate
                            </td>
                            <td style="text-align: center; vertical-align: middle">
                                <input type="text" id="innum@(item.ProductId)" name="innum@(item.ProductId)" onkeyup="changeInNum(@item.ProductId,@integrate)" maxlength="5"  class="text"  style="width:30px;height:12px;" value="@item.Num"/><br />
                                <span id="intip@(item.ProductId)" style="color:Red;font-size:9px"></span>
                                <input type="hidden" id="inremain@(item.ProductId)" name="inremain@(item.ProductId)" value="@item.productRemain" />
                            </td>
                            <td style="text-align: center; color: #DC143C;">
                                <span id="inmoney@(item.ProductId)" name="inmoney@(item.ProductId)">@sumintegrate</span>
                            </td>
                        </tr>
                        }
                        j++;
                    }
                        <input type="hidden" name="IntegratIds" id="IntegratIds" value="@inids" />
                    j++;
                        <tr>
                            <td colspan="4" style="text-align: right; font-weight: bold;">
                                总积分
                            </td>
                            <td style="text-align: center; font-size: 19px; color: #DC143C; font-weight: bold;">
                                <span id="inmoney" name="inmoney">@totalintegrate</span><input type="hidden" name="intotalmoney" id="intotalmoney" value="@totalintegrate" />
                            </td>
                        </tr>
                    
                }
                    }
                </tbody>
            </table>
            }
         
            <table class="table">
                <tr>
                    <td style="text-align: right;">
                        <input type="submit" id="submitBtn" class="btn btn-danger" style="margin-top: 10px;
                            font-size: 17px;" value="提交订单" />
                    </td>
                </tr>
                <tr>
                    <td style="text-align: right; color: Red">@message
                    </td>
                </tr>
            </table>
        }
    </div>
    </form>
</div>
@section tail{
    <script type="text/javascript">

        $("formSo").submit(function () {
            $("#submitBtn").val("正在提交...");
            $("#submitBtn").attr("disabled", "disabled");
        });    
    </script>
}
